#include "memmap.h"
#include <stdio.h>
#include "hexdump.h"

#define BSPMD_DISPLAY_BYTE_WIDTH 16

static int bspmd_(unsigned long startAddr, unsigned long endAddr)
{
	unsigned long ul_addr = 0;
	void *p_mem  = NULL;
	unsigned long len;

    ul_addr = startAddr;
	len = endAddr - startAddr + 1;

	p_mem = memmap(ul_addr, len);
	if (p_mem == NULL)
    {
		printf("Memory Map error");
        return -1;
    }
	bsp_hexdump(stdout, p_mem, startAddr, len, BSPMD_DISPLAY_BYTE_WIDTH);
	

	return 0;
}

int bspmd(int argc, char *argv[])
{
    unsigned long startAddr, endAddr;
    
    if (2 == argc)
    {
        sscanf(argv[1], "%lx", &startAddr);
        bspmd_(startAddr, startAddr + (unsigned long)BSPMD_DISPLAY_BYTE_WIDTH * BSPMD_DISPLAY_BYTE_WIDTH);
    }
    else if (3 == argc)
    {
        sscanf(argv[1], "%lx", &startAddr);
        sscanf(argv[2], "%lx", &endAddr);
        bspmd_(startAddr, endAddr);
    }
    else 
    {
        printf("Use: bspmd startAddr [endAddr]\n");
    }
    return 0;
}